<?php

// 连接 Redis 服务
$redis = new Redis();
$redis->connect('172.17.0.4', 6379);
echo "Connection to server successfully <br/>" . PHP_EOL; // PHP_EOL只是用于终端输出换行, <br/>用于浏览器换行

// 检测服务运行状态
if ($redis->ping()) {
      $color = 'green';
      $state = 'running';
} else {
      $color = 'red';
      $state = 'stop';
}
echo "Server state: <span style=\"color: {$color}\">{$state}</span> <br/>" . PHP_EOL;

// 设置 redis 字符串数据
$redis->set("words", "hello redis~");
// 获取存储的数据并输出
echo "Stored string in redis:: <span style='color: green;'>" . $redis->get("words") . '</span> <br/>' . PHP_EOL;
